import { ckeckCode } from '@/api/pre/insystem'
import {validateStr} from '@/util/validate'

const validateString = (rule, value, callback) => {
  if (validateStr(value)[0]) {
    callback(new Error(validateStr(value)[1]))
  } else {
    callback()
  }
}
const validateSysCode = (rule, value, callback) => {
  var inSys = {
    inSysCode: value
  }
  ckeckCode(inSys).then(response => {
    if (window.boxType === 'edit') callback()
    const result = response.data.data
    if (result.length > 0) {
      callback(new Error('该接入项目编码以存在'))
    } else {
      callback()
    }
  })

}

export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  align: 'center',
  searchMenuSpan: 6,
  column: [{
    label: '项目ID',
    prop: 'sysId',
    display: false,
    hide: true,
    showColumn: false
  },{
    label: '项目名称',
    prop: 'name',
    align: 'center',
    maxlength: 50,
    showWordLimit: true,
    search: true,
    span: 24,
    rules: [{
      required: true,
      message: '请输入项目名称',
      trigger: 'blur'
    }]
  }, {
    label: '项目编码',
    prop: 'code',
    align: 'center',
    maxlength: 50,
    showWordLimit: true,
    search: true,
    editDisabled: true,
    span: 24,
    rules: [
      {required: true, message: '请输入项目编码', trigger: 'blur'},
      {validator: validateSysCode, trigger: 'blur' },
      { validator: validateString, trigger: 'blur'}
      ]
  }, {
    label: '备注',
    prop: 'remark',
    align: 'center',
    maxlength: 200,
    showWordLimit: true,
    span: 24,
    type: 'textarea'
  }]
}
